package com.ccys.cms.controller.userManagement;

import com.ccys.cms.service.userManagement.FavouritePrescriptionService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.userManagement.FavouritePrescriptionDetailDto;
import com.ccys.db.dto.userManagement.FavouritePrescriptionDto;
import com.ccys.db.vo.userManagement.FavouritePrescriptionDetailPageQueryVo;
import com.ccys.db.vo.userManagement.FavouritePrescriptionPageQueryVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.text.ParseException;

/**
 * @program: WhiteCoat
 * @description: 处方管理接口
 * @author: ZhangJingCan
 * @create: 2023-12-22 09:40
 **/

@RestController
@RequestMapping("userManagement")
@Api(tags = "userManagement-处方管理接口")
public class FavouritePrescriptionController {

    @Autowired
    private FavouritePrescriptionService favouritePrescriptionService;


    @PostMapping("favouritePrescription")
    @ApiOperation("保存处方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "groupId", value = "国家ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult saveFavouritePrescription(@ApiIgnore FavouritePrescriptionDto dto) {
        return favouritePrescriptionService.saveFavouritePrescription(dto);
    }

    @PutMapping("favouritePrescription")
    @ApiOperation("修改处方")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "name", value = "name", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "groupId", value = "国家ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult editFavouritePrescription(@ApiIgnore FavouritePrescriptionDto dto) {
        return favouritePrescriptionService.saveFavouritePrescription(dto);
    }

    @DeleteMapping("favouritePrescription")
    @ApiOperation("根据ID删除处方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deleteFavouritePrescription(@ApiIgnore FavouritePrescriptionDto dto) {
        return favouritePrescriptionService.deleteFavouritePrescription(dto);
    }


    @GetMapping("favouritePrescription")
    @ApiOperation("分页查询处方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name模糊查询", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "groupId", value = "国家ID/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0/1,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:t1.name,total,t1.status,t2.user_fullname,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<FavouritePrescriptionPageQueryVo>, Object> findPageFavouritePrescription(@ApiIgnore FavouritePrescriptionDto dto) {
        return favouritePrescriptionService.findPageFavouritePrescription(dto);
    }


    @PutMapping("favouritePrescription/status")
    @ApiOperation("根据ID修改处方状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateFavouritePrescriptionStatus(FavouritePrescriptionDto dto) {
        return favouritePrescriptionService.updateFavouritePrescriptionStatus(dto);
    }

    @PostMapping("favouritePrescription/favouritePrescriptionDetail")
    @ApiOperation("保存处方详情")
    public ResponseResult saveFavouritePrescriptionDetail(@RequestBody FavouritePrescriptionDetailDto dto) throws ParseException {
        return favouritePrescriptionService.saveFavouritePrescriptionDetail(dto);
    }

    @DeleteMapping("favouritePrescription/favouritePrescriptionDetail")
    @ApiOperation("根据ID删除处方详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deleteFavouritePrescriptionDetail(@ApiIgnore FavouritePrescriptionDetailDto dto) {
        return favouritePrescriptionService.deleteFavouritePrescriptionDetail(dto);
    }

    @GetMapping("favouritePrescription/favouritePrescriptionDetail")
    @ApiOperation("分页查询处方详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "favouritePrescriptionId", value = "处方主表ID", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<FavouritePrescriptionDetailPageQueryVo>, Object> findPageFavouritePrescriptionDetail(@ApiIgnore FavouritePrescriptionDetailDto dto) {
        return favouritePrescriptionService.findPageFavouritePrescriptionDetail(dto);
    }

}
